
define([
	"require",
    'config/appregister',
    "i18n",
    "business/personMine/services/httpServices",
	'business/blogpost/service/blogHttp',    
    "business/personMine/services/mineDirective",
    "business/services/personCenterComp",
    "business/services/detailNavComp",
    "business/services/filter",
	"business/services/commentComp",
	"domReady"
],function(require,app,i18n,httpService,httpServices,constant){
    app.controller('othersBlogCtrl', function($scope,$state,$stateParams,$rootScope,$sce,setUrl) {
		var currentUserId=$rootScope.userLoginInfo.data.userId;
        $scope.i18n = i18n;
        $scope.goToEng = function(state){
            if(!state){
                return
            }
            $state.go(state,{userId:$stateParams.userId});
        };
        $scope.userId = $stateParams.userId ;



//
		//点击列表跳转详情
		
		$scope.jump = function(blogId) {
			$state.go("othersBlogInfo",{blogId:blogId,userId:$scope.userId});

//			var url = "http://www.gongchengjie.cn/#/blogxq?blogid="+blogId;
//			window.open(url,'_blank');			
		};
		//编辑
		$scope.edit = function(blogId) {
//			$state.go("blogmod",{blogid:blogId});
			var url = "http://www.gongchengjie.cn/#/blogmod?blogid="+blogId;
			window.open(url,'_blank');			
			
		};
		//人气博文跳转
		$scope.goBlogDetail = function(id,type,userId){
			if(type == 1) {
				$state.go("outIndexCtrl.bwDetailCtrl",{outBlogId:id,companyId:userId});
				return;
			}
			if(type == 0) {
				if(currentUserId!=userId){
					$state.go("othersBlogInfo",{blogId:id,userId:userId});
					return;
				}else{
					$state.go("blogxq",{blogId:id,userId:userId});
					return;
				}

			}
		};
		
		//删除
		$scope.delblog = function() {
			var req = {
				type:'GET',
				uri:'del',
				data:{
					blogid:$scope.indexid
				}
			};
			httpServices.getmarkService(req).success(function(data) {
				if(!data)return;
				$scope.$apply(function() {
					if(data.code == 0) {
						console.log("删除成功");
						$(".delTip").hide();
						getList();
					}else {
						console.log(data.msg);
					}
				});
			}).error(function() {
				console.log("删除博文请求失败");
			})
		};
		//弹出删除确认提示
		$scope.deleteblog = function(blogid) {
			$scope.indexid = blogid;
			$(".delTip").show();
		};
		//取消删除
		$scope.close = function() {
			$(".delTip").hide();
		};
		//发布博文
		$scope.editnew = function() {
//			var url = setUrl.getUrl('blogpost');
			var url = "http://www.gongchengjie.cn/#/blogpost";
//			var url = "http://116.62.10.111:8020/elink/index.html#/blogpost";
			
			window.open(url,'_blank');
		};
		//中间菜单跳转
		$scope.gona = function(num) {
			if(num == 1) $state.go("myaccount");
			if(num == 2) $state.go("homepage");
			if(num == 3) $state.go("myMainPage");
			if(num == 4) $state.go("resume.posted");
		};
		//公共参数
		$scope.listParams = {
			type: 0+','+2,
			pageNo: 1,
			pageSize: 10,
			all: false
		};
		//第一次渲染请求
		getList();
		//请求tade博文列表方法
		function getList() {
			var req = {
				type:'GET',
				uri:'getBlogListByUserId',
				data:{
					userId:$scope.userId,
					type:0,
					pageNo:$scope.listParams.pageNo,
					pageSize:$scope.listParams.pageSize,
					all:$scope.listParams.all
				}
			};
			httpServices.getblogHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function(){
					if(data.code==0&&data.data.list.length > 0) {
						$sce.trustAsHtml(data.data.list.content);
						$(".lbox-ul").show();
						$(".fenye").show();
						$(".nodata").hide();
						$scope.qqq = data.data.list;
						$scope.totalItem = data.data.Pagination.totalCount;
						$scope.listParams.pageNo = data.data.Pagination.pageNo;
						$scope.listParams.pageSize = data.data.Pagination.pageSize;
						getListModel();
					} else {
						$(".nodata").show();
						$(".lbox-ul").hide();
						$(".fenye").hide();
					}						
				});
							
			}).error(function(data){
				alert("博文列表请求失败");
			});
		}
		//获取人气博文
		getHotBlog();
		function getHotBlog() {
			var req = {
				type:'GET',
				uri:'getGreetBlog',
				data:{
					count:10
				}
			};
			httpServices.getblogHttpService(req).success(function(data){
				if(!data)return;
				$scope.$apply(function() {
					$scope.hotBlog = data.data;
				});				
			}).error(function(data){
				alert("获取本周人气博文请求失败")
			});
		};
		//分页方法
		function getListModel() {
			$scope.paginationConf = {
				currentPage: $scope.listParams.pageNo,
				totalItems: $scope.totalItem,
				//每页预览条数
				itemsPerPage: $scope.listParams.pageSize,
				//分页总数
				numberOfPages: Math.ceil($scope.totalItem / $scope.listParams.pageSize),
				// 实际分页长度
				pagesLength: 5,
				perPageOptions: [10, 20, 30, 40, 50],
				onChange: function(currentPage) {
					if(currentPage) {
						$scope.paginationConf.currentPage = currentPage;
					}
					$scope.list = [];
					$scope.listParams.pageNo = $scope.paginationConf.currentPage;
					getList();
				}
			};
		};
		//过滤数据
		$scope.contenthtml = function(str) {
			str.replace(/<[^>]+>/g,"");
			str = str.substring(0,64);
			var thestr = "<p>"+str+"...</p>"
			return thestr
		};		
		
		
		
		
		
	        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        

    })
});
